'use strict';

module.exports = app => {
  const { model } = app;
  const { UUID, STRING, INTEGER } = app.Sequelize;

  const UserInfo = model.define(
    'UserInfo',
    {
      user_id: {
        type: UUID,
      },
      email: {
        type: STRING(50),
        allowNull: false,
      },
      nick_name: {
        type: STRING(50),
        allowNull: false,
      },
      avatar: {
        type: STRING(255),
        allowNull: false,
      },
      age: {
        type: INTEGER,
        allowNull: false,
      },
    },
    {
      tableName: 'sys_user_info',
    }
  );

  UserInfo.removeAttribute('id');

  UserInfo.associate = function() {
    const { Sys: { User, UserInfo } } = model;
    UserInfo.belongsTo(User, { as: 'user', foreignKey: 'user_id' });
  };

  return UserInfo;
};
